package com.anyou.mall.use.service.impl;

import java.util.List;

import com.anyou.mall.use.param.NoticeParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.anyou.mall.use.mapper.UserNoticeMapper;
import com.anyou.mall.use.domain.UserNotice;
import com.anyou.mall.use.service.IUserNoticeService;

/**
 * 用户通知Service业务层处理
 *
 * @author gaochaohao
 * @date 2022-04-07
 */
@Service
public class UserNoticeServiceImpl extends ServiceImpl<UserNoticeMapper,UserNotice> implements IUserNoticeService
{
    @Autowired
    private UserNoticeMapper userNoticeMapper;

    /**
     * 查询用户通知
     *
     * @param noticeId 用户通知主键
     * @return 用户通知
     */
    @Override
    public UserNotice selectUserNoticeByNoticeId(Long noticeId)
    {
        return userNoticeMapper.selectUserNoticeByNoticeId(noticeId);
    }

    /**
     * 查询用户通知列表
     *
     * @param userNotice 用户通知
     * @return 用户通知
     */
    @Override
    public List<UserNotice> selectUserNoticeList(UserNotice userNotice)
    {
        return userNoticeMapper.selectUserNoticeList(userNotice);
    }

    /**
     * 新增用户通知
     *
     * @param userNotice 用户通知
     * @return 结果
     */
    @Override
    public int insertUserNotice(UserNotice userNotice)
    {
        return userNoticeMapper.insertUserNotice(userNotice);
    }

    /**
     * 修改用户通知
     *
     * @param userNotice 用户通知
     * @return 结果
     */
    @Override
    public int updateUserNotice(UserNotice userNotice)
    {
        return userNoticeMapper.updateUserNotice(userNotice);
    }

    /**
     * 批量删除用户通知
     *
     * @param noticeIds 需要删除的用户通知主键
     * @return 结果
     */
    @Override
    public int deleteUserNoticeByNoticeIds(Long[] noticeIds)
    {
        return userNoticeMapper.deleteUserNoticeByNoticeIds(noticeIds);
    }

    /**
     * 删除用户通知信息
     *
     * @param noticeId 用户通知主键
     * @return 结果
     */
    @Override
    public int deleteUserNoticeByNoticeId(Long noticeId)
    {
        return userNoticeMapper.deleteUserNoticeByNoticeId(noticeId);
    }

    @Override
    public boolean deleteDataByPlatformNoticeId(Long platformNoticeId) {
        boolean removeById = this.remove(new QueryWrapper<UserNotice>().lambda()
                .eq(UserNotice::getSourceId, platformNoticeId)
                .eq(UserNotice::getNoticeType, 2));
        return removeById;
    }
    /**
     * 后台管理消息列表
     * @return
     */
    @Override
    public List<UserNotice> getAdminNoticeList(NoticeParam param) {
        LambdaQueryWrapper<UserNotice> eq = new LambdaQueryWrapper<UserNotice>()
                .eq(UserNotice::getUserId, param.getMiniUserId());
        eq.eq(UserNotice::getNoticeType,1);

        switch (param.getType()) {
            case 0:

                break;
            case 1:
                eq.eq(UserNotice::getChildType,21);
                break;
            case 2:
                eq.eq(UserNotice::getChildType,22);
                break;
            case 3:
                eq.in(UserNotice::getChildType,23,24);
                break;
            default:
                break;
        }
        List<UserNotice> list = this.list(eq);
        return list;
    }
}
